package com.atguigu.gulimall.seckill.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gulimall.order.entity.OrderInfo;
import com.atguigu.gulimall.seckill.entity.SeckillGoods;
import com.atguigu.gulimall.seckill.service.SeckillBizService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author nicc
 * @version 1.0
 * @className SeckillRpcController
 * @date 2022-10-28 07:05
 */
@RestController
@RequestMapping("/api/inner/seckill")
public class SeckillRpcController {

    @Autowired
    SeckillBizService seckillBizService;

    /**
     * 获取秒杀单
     * @param skuId
     * @return
     */
    @GetMapping("/order/{skuId}")
    public Result<OrderInfo> getSeckillOrder(@PathVariable("skuId") Long skuId){
        OrderInfo orderInfo =  seckillBizService.getSeckillOrder(skuId);
        return Result.ok(orderInfo);
    }


    /**
     * 获取今天参与秒杀的所有商品
     * @return
     */
    @GetMapping("/goods/list/today")
    public Result<List<SeckillGoods>> getCurrentDaySeckillGoods(){

        List<SeckillGoods> goods = seckillBizService.getCurrentDaySeckillGoods();
        return Result.ok(goods);
    }

    /**
     * 秒杀商品详情数据
     * @param skuId
     * @return
     */
    @GetMapping("/goods/detail/{skuId}")
    public Result<SeckillGoods> getDetail(@PathVariable("skuId") Long skuId){
        SeckillGoods seckillGoods = seckillBizService.getGoodsDetail(skuId);
        return Result.ok(seckillGoods);
    }

}
